package util

import (
	"bytes"
	"fmt"
	"runtime"
	"runtime/debug"
	"strconv"
)

func PanicLog() {
	if err := recover(); nil != err {
		buffer := bytes.Buffer{}
		for i := 2; ; i++ {
			caller, file, line, ok := runtime.Caller(i)
			if !ok {
				break
			}
			buffer.WriteString(file)
			buffer.WriteString(":")
			buffer.WriteString(strconv.Itoa(line))
			buffer.WriteString(fmt.Sprint(caller))
		}
		log.Errorf("SYSTEM ACTION PANIC: %v, stack: %v", err, string(debug.Stack()))
	}
}
